package com.mf.ergate.controller.bo.pt;

import com.mf.ergate.api.bo.pt.PtOrderInfoRemoteService;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderInfoCreateDto;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderInfoDeleteDto;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderInfoQueryDto;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderInfoUpdateDto;
import com.mf.ergate.api.bo.pt.model.vo.PtOrderInfoVo;
import com.mf.ergate.common.utils.MfBeanUtils;
import com.mf.ergate.domain.model.bo.pt.PtOrderInfoEntity;
import com.mf.ergate.service.bo.pt.PtOrderInfoService;
import com.mf.framework.common.model.Page;
import com.mf.framework.common.model.RemotePage;
import com.mf.framework.common.model.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 跑腿订单信息Controller
 * User: zhaoming
 * DateTime: 2019-01-28
 * To change this template use File | Settings | File Templates.
 */
@RestController
public class PtOrderInfoController implements PtOrderInfoRemoteService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private PtOrderInfoService ptOrderInfoService;

    /**
     * 新增
     * @param ptOrderInfoCreateDto 跑腿订单信息新增Dto
     * @return 跑腿订单信息
     */
    public Result<PtOrderInfoVo> insert(@RequestBody PtOrderInfoCreateDto ptOrderInfoCreateDto) {
        PtOrderInfoEntity ptOrderInfoEntity = MfBeanUtils.copyObject(ptOrderInfoCreateDto, PtOrderInfoEntity.class);
        ptOrderInfoEntity = ptOrderInfoService.insert(ptOrderInfoEntity);
        PtOrderInfoVo ptOrderInfoVo = MfBeanUtils.copyObject(ptOrderInfoEntity, PtOrderInfoVo.class);
        return new Result<>(ptOrderInfoVo);
    }

    /**
     * 根据唯一编号更新
     * @param ptOrderInfoUpdateDto 跑腿订单信息更新Dto
     * @return 执行结果
     */
    public Result<Boolean> updateByUniqueNo(@RequestBody PtOrderInfoUpdateDto ptOrderInfoUpdateDto) {
        PtOrderInfoEntity ptOrderInfoEntity = MfBeanUtils.copyObject(ptOrderInfoUpdateDto, PtOrderInfoEntity.class);
        Boolean flag = ptOrderInfoService.updateByUniqueNo(ptOrderInfoEntity);
        return new Result<>(flag);
    }

    /**
     * 根据唯一编号删除(逻辑删除)
     * @param ptOrderInfoDeleteDto 跑腿订单信息删除Dto
     * @return 结果集
     */
    public Result<Boolean> deleteByUniqueNo(@RequestBody PtOrderInfoDeleteDto ptOrderInfoDeleteDto){
        PtOrderInfoEntity ptOrderInfoEntity = MfBeanUtils.copyObject(ptOrderInfoDeleteDto, PtOrderInfoEntity.class);
        Boolean flag = ptOrderInfoService.deleteByUniqueNo(ptOrderInfoEntity);
        return new Result<>(flag);
    }

    /**
     * 根据唯一编号查询
     * @param uniqueNo 唯一编号
     * @return 跑腿订单信息
     */
    public Result<PtOrderInfoVo> selectByUniqueNo(@RequestBody String uniqueNo) {
        PtOrderInfoEntity ptOrderInfoEntity = ptOrderInfoService.selectByUniqueNo(uniqueNo);
        PtOrderInfoVo ptOrderInfoVo = MfBeanUtils.copyObject(ptOrderInfoEntity, PtOrderInfoVo.class);
        return new Result<>(ptOrderInfoVo);
    }

    /**
     * 根据条件查询
     * @param ptOrderInfoQueryDto 跑腿订单信息查询Dto
     * @return 跑腿订单信息列表
     */
    public Result<List<PtOrderInfoVo>> selectByCondition(@RequestBody PtOrderInfoQueryDto ptOrderInfoQueryDto) {
        List<PtOrderInfoEntity> ptOrderInfoEntities = ptOrderInfoService.selectByCondition(ptOrderInfoQueryDto);
        List<PtOrderInfoVo> ptOrderInfoVos = MfBeanUtils.copyList(ptOrderInfoEntities, PtOrderInfoVo.class);
        return new Result<>(ptOrderInfoVos);
    }

    /**
     * 根据条件查询数量
     * @param ptOrderInfoQueryDto 跑腿订单信息查询Dto
     * @return 数量
     */
    public Result<Integer> selectCount(@RequestBody PtOrderInfoQueryDto ptOrderInfoQueryDto) {
        return new Result<>(ptOrderInfoService.selectCount(ptOrderInfoQueryDto));
    }

    /**
     * 根据条件分页查询
     * @param remotePage 远程分页对象
     * @return 跑腿订单信息分页列表
     */
    public Result<Page<PtOrderInfoVo>> selectPage(@RequestBody RemotePage<PtOrderInfoQueryDto> remotePage){
        Page<PtOrderInfoEntity> ptOrderInfoEntityPage = ptOrderInfoService.selectPage(remotePage.getPage(), remotePage.getObj());
        Page<PtOrderInfoVo> page = MfBeanUtils.copyPage(ptOrderInfoEntityPage, PtOrderInfoVo.class);
        return new Result<>(page);
    }

}